package main

import (
	"fmt"
	"os"
)

func WriteFile(path string) {
	create, err := os.Create(path)
	if err != nil {
		fmt.Println("err :", err)
		return
	}

	defer create.Close()

	for i := 0; i < 10; i++ {
		buf := fmt.Sprintf("i = %v\n", i)
		n, err := create.WriteString(buf)
		if err != nil {
			fmt.Println("err： ", err)
			return
		}
		fmt.Println("n = ", n)
	}
}

func ReadFile(path string) {
	open, err := os.Open(path)
	if err != nil {
		fmt.Println("err : ", err)
	}

	defer open.Close()

	buf := make([]byte, 1024)

	n, _ := open.Read(buf)

	fmt.Println(string(buf[:n]))
}
func main() {
	path := "./demo.txt"
	WriteFile(path)
	ReadFile(path)
}
